/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package assignment_cp3120.DAO.mysqlDAO;

import assignment_cp3120.DAO.GST_PromoDAO;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;

/**
 *
 * @author Administrator
 */
public class MysqlGST_promoDAO implements GST_PromoDAO{

    public int setGST(int gst) {
        int result = 0;
        Connection c = MysqlDA0Factory.createConnection();
        try{
            Statement statement = c.createStatement();
            result = statement.executeUpdate(
                    "UPDATE 3120S109g09.GST_PROMO SET GST = "
                    + gst
                    );
        }
        catch(SQLException e){System.out.println(e);}
        return result;
    }

    public int getGST() {
        int gst = 0;

        Connection c = MysqlDA0Factory.createConnection();
        try{
            Statement statment = c.createStatement();
            ResultSet rs = statment.executeQuery(
                    "SELECT GST FROM GST_PROMO");
            if(rs.isBeforeFirst()){
                rs.next();
            }
            if(rs.first()){
                gst = rs.getInt("GST");
            }
            c.close();
        }catch(SQLException e){gst = 0;}
        return gst;
    }
        public int setPromo(int promo) {
        int result = 0;
        Connection c = MysqlDA0Factory.createConnection();
        try{
            Statement statement = c.createStatement();
            result = statement.executeUpdate(
                    "UPDATE 3120S109g09.GST_PROMO SET PROMO = "
                    + promo
                    );
        }
        catch(SQLException e){System.out.println(e);}
        return result;
    }

    public int getPromo() {
        int promo = 0;

        Connection c = MysqlDA0Factory.createConnection();
        try{
            Statement statment = c.createStatement();
            ResultSet rs = statment.executeQuery(
                    "SELECT PROMO FROM GST_PROMO");
            if(rs.isBeforeFirst()){
                rs.next();
            }
            if(rs.first()){
                promo = rs.getInt("PROMO");
            }
            c.close();
        }catch(SQLException e){promo = 0;}
        return promo;
    }
}
